package com.example.sixthweek;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.google.android.material.tabs.TabLayout;

public class CountRate extends AppCompatActivity {
    private static final String TAG = "why";
    TextView tv2;
    EditText editText;
    String detailStr;
    Float rate = 0f;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_count_rate);
        Intent intent = getIntent();
        String titleStr = intent.getStringExtra("titleKey");
        detailStr = intent.getStringExtra("detailKey");

        TextView tv1 = findViewById(R.id.tv1);
        tv1.setText(titleStr);
        
        rate = 100f/Float.parseFloat(detailStr);
        Log.i(TAG, "onCreate: rate" +rate);

        editText = findViewById(R.id.ed);
        editText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                tv2 = CountRate.this.findViewById(R.id.tv2);
                if(editable.length() > 0){
                    Float tv = Float.parseFloat(editable.toString());
                    tv2.setText("结果为"+tv*rate);
                    Log.i(TAG, "afterTextChanged: tv" + tv);
                }else {
                    tv2.setText("");
                }
            }
        });
        

    }
}